package gam.n1.be.b;

import gam.n1.areas.Area;
import gam.n1.be.Behavioral;
import gam.n1.e.bh.ActionBehavioralEvent;
import org.bukkit.Bukkit;

public abstract class BaseBehavioral implements Behavioral {
    protected Area g;
    private volatile boolean r;
    public BaseBehavioral(Area area){
        this.g = area;
        this.r = false;
    }
    @Override
    public void accept(Area gArea) {
    }

    @Override
    public void tick() {
        r = true;
        ActionBehavioralEvent e = new ActionBehavioralEvent(this);
        Bukkit.getPluginManager().callEvent(e);
        r = e.isCancelled();
        if (isRunning() && g.isRunning()) {
            if (e.getBefore() != null) e.getBefore().tick();
            aP();
            if (e.getAfter() != null) e.getAfter().tick();
        }
    }

    @Override
    public boolean isRunning() {
        return r;
    }

    protected void aP(){
    }
}
